package com.heima.wemedia;

import com.heima.file.service.FileStorageService;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import javax.annotation.Resource;
import java.io.File;
import java.io.FileInputStream;

@SpringBootTest(classes = WemediaApplication.class)
@RunWith(SpringRunner.class)
public class OssDemo {
    @Resource
    private FileStorageService fileStorageService;

    @Value("${file.oss.web-site}")
    String webSite;

    @Value("${file.oss.profix}")
    String profix;

    @Test
    public void testFileUpload() throws Exception {

        FileInputStream inputStream = new FileInputStream(new File("D:\\anythingstorage\\Img1\\182cdda7-3cd8-4187-bf44-6d7fd29f188c.jpg"));

        String store = fileStorageService.store(profix, "aaa1.jpg", inputStream);
        System.out.println(webSite+store);

    }


    @Test
    public void testFileDelete() throws Exception {

        //删除文件
        fileStorageService.delete("material/2021/4/20210413/aaa1.jpg");
    }
}
